package com.lightsaber.trade.cloth.entity.category;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.lightsaber.trade.core.entity.BaseEntity;
import com.lightsaber.trade.cloth.entity.planning.PlanningStatus;

@Entity
@Table(name = "MHPP_CATEGORY_NODE")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "IS_LEAF_NODE", discriminatorType = DiscriminatorType.INTEGER)
public class CategoryNode extends BaseEntity {

    private static final long serialVersionUID = -6258134905580417570L;

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CATEGORY_ID", unique = true, updatable = false, nullable = true)
    private Category category;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PARENT_ID")
    private CategoryNode parent;

    @Column(name = "NAME", nullable = false, length = 100)
    private String name;

    @Enumerated(EnumType.STRING)
    @Column(name = "INPUT_TYPE", length = 30)
    private InputType inputType;

    @Column(name = "IS_LEAF_NODE", insertable = false, updatable = false)
    private Integer isLeafNode;

    @Column(name = "IS_DISCIPLINE_VIEW")
    private Integer isDisciplineView;

    @Column(name = "IS_INHERIT_PARENT_NODE", length = 10)
    private Integer isInheritParentNode;

    @Enumerated(EnumType.STRING)
    @Column(name = "SOURCE_TYPE", length = 50)
    private SourceType sourceType;

    @Column(name = "REMARKS", nullable = true, length = 4000)
    private String remarks;

    @OneToMany(mappedBy = "categoryNode", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private List<CategoryOwner> categoryOwners;

    @OneToMany(mappedBy = "categoryNode", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<CategoryPlanner> categoryPlanners;

    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<CategoryNode> children;

    @OneToMany(mappedBy = "ownerNode", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<Category> ownedBranchTrees;

    @Enumerated(EnumType.STRING)
    @Column(name = "LEVEL_2_STATUS", nullable = true)
    private PlanningStatus level2status;

    public String getName() {
        return name;
    }

    public void setName(final String name) {
        this.name = name;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(final String remarks) {
        this.remarks = remarks;
    }

    public CategoryNode getParent() {
        return parent;
    }

    public void setParent(final CategoryNode parent) {
        this.parent = parent;
    }

    public InputType getInputType() {
        return inputType;
    }

    public void setInputType(final InputType inputType) {
        this.inputType = inputType;
    }

    public Integer getIsLeafNode() {
        return isLeafNode;
    }

    protected void setIsLeafNode(final Integer isLeafNode) {
        this.isLeafNode = isLeafNode;
    }

    public Integer getIsDisciplineView() {
        return isDisciplineView;
    }

    public void setIsDisciplineView(final Integer isDisciplineView) {
        this.isDisciplineView = isDisciplineView;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(final Category category) {
        this.category = category;
    }

    public List<CategoryOwner> getCategoryOwners() {
        return categoryOwners;
    }

    public void setCategoryOwners(final List<CategoryOwner> categoryOwners) {
        this.categoryOwners = categoryOwners;
    }

    public List<CategoryPlanner> getCategoryPlanners() {
        return categoryPlanners;
    }

    public void setCategoryPlanners(final List<CategoryPlanner> categoryPlanners) {
        this.categoryPlanners = categoryPlanners;
    }

    public SourceType getSourceType() {
        return sourceType;
    }

    public void setSourceType(final SourceType sourceType) {
        this.sourceType = sourceType;
    }

    public List<CategoryNode> getChildren() {
        return children;
    }

    public void setChildren(final List<CategoryNode> children) {
        this.children = children;
    }

    public List<Category> getOwnedBranchTrees() {
        return ownedBranchTrees;
    }

    public void setOwnedBranchTrees(final List<Category> ownedBranchTrees) {
        this.ownedBranchTrees = ownedBranchTrees;
    }

    public Integer getIsInheritParentNode() {
        return isInheritParentNode;
    }

    public void setIsInheritParentNode(final Integer isInheritParentNode) {
        this.isInheritParentNode = isInheritParentNode;
    }

    public PlanningStatus getLevel2status() {
        return level2status;
    }

    public void setLevel2status(final PlanningStatus level2status) {
        this.level2status = level2status;
    }

}
